package bb.lanxing.fragment.sport;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import bb.lanxing.R;
import bb.lanxing.activity.sport.PanelSettingActivity;
import bb.lanxing.adapter.sport.PanelSettingTypeAdapter;
import bb.lanxing.fragment.base.BaseFragment;

public class PanelSettingTypeFragment extends BaseFragment {
    private RecyclerView mRecyclerView;
    private PanelSettingTypeAdapter mPanelSettingTypeAdapter;
    private int mBigType;
    private int[] typeList;
    public int mSelectedTab = -1;

    public PanelSettingTypeFragment(int bigType, int[] types) {
        mBigType = bigType;
        typeList = types;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_sport_record_list, container, false);

        mRecyclerView = view.findViewById(R.id.recyclerView);
        mRecyclerView.setLayoutManager(new GridLayoutManager(getContext(), 2));
        getPanelSettingTypeAdapter();
        mRecyclerView.setAdapter(mPanelSettingTypeAdapter);
        return view;
    }

    public PanelSettingTypeAdapter getPanelSettingTypeAdapter() {
        if (mPanelSettingTypeAdapter == null) {
            mPanelSettingTypeAdapter = new PanelSettingTypeAdapter(mBigType, typeList);
            mPanelSettingTypeAdapter.setOnItemClickListener(position -> {
                mPanelSettingTypeAdapter.updateSelectedItem(mSelectedTab, position);
                PanelSettingActivity activity = ((PanelSettingActivity) getActivity());
                activity.setSportItem(activity.CATEGORY[mSelectedTab].getTypes()[position]);
                activity.mPanelSettingTabAdapter.removeUnselectedItem();
            });
        }
        return mPanelSettingTypeAdapter;
    }
}